
const express = require('express')
const router = express.Router()

// 获取门店列表
router.get('/list', (req, res) => {
  const stores = [
    {
      id: 'ST-001',
      name: '朝阳门店',
      location: '北京市朝阳区',
      scanRate: 99.2,
      lastDelivery: '2024-11-01 08:00:00'
    },
    {
      id: 'ST-002',
      name: '静安店',
      location: '上海市静安区',
      scanRate: 97.8,
      lastDelivery: '2024-11-01 07:30:00'
    }
  ]
  res.json(stores)
})

// 门店扫码收货
router.post('/receive', (req, res) => {
  const { storeId, items, temperature } = req.body
  
  // 验证温度
  if (temperature > 4) {
    return res.status(400).json({
      success: false,
      message: '温度过高，拒绝收货'
    })
  }
  
  const receipt = {
    id: `RC${Date.now()}`,
    storeId,
    items,
    temperature,
    status: '已收货',
    timestamp: new Date().toLocaleString('zh-CN')
  }
  
  res.json({ success: true, receipt })
})

// 智能补货
router.post('/replenish', (req, res) => {
  const { storeId, items } = req.body
  
  // 计算补货需求
  const replenishment = {
    id: `RP${Date.now()}`,
    storeId,
    items: items.map(item => ({
      ...item,
      suggestedQuantity: Math.ceil(item.currentStock * 1.2),
      reason: '库存预警'
    })),
    createdAt: new Date().toLocaleString('zh-CN')
  }
  
  res.json({ success: true, replenishment })
})

module.exports = router
